package com.whfc.openapi.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * @Description: 乐橙云token
 * @author: qzexing
 * @version: 1.0
 * @date: 2020/4/29 22:06
 */
@Repository
public class ImouApiTokenRedisDaoImpl implements ImouApiTokenRedisDao {

    public static final String key = "imou-api::token::%s";

    public static final long timeout = 3;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void setAccessToken(String appKey, String accessToken) {
        String cacheKey = String.format(key, appKey);
        redisTemplate.opsForValue().set(cacheKey, accessToken, timeout, TimeUnit.DAYS);
    }

    @Override
    public String getAccessToken(String appKey) {
        String cacheKey = String.format(key, appKey);
        return redisTemplate.opsForValue().get(cacheKey);
    }

}
